/****************************************************************************

	COPYRIGHT(C) MAXSI SOFTWARE, JONAS 'SORTIE' TERMANSEN 2008, 2009, 2010

    This file is part of Maxsi Distribution.

    Maxsi Distribution is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Maxsi Distribution is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with Maxsi Distribution. If not, see <http://www.gnu.org/licenses/>.

	*/ #include "MaxsiDistributionContributors.h" /*

	If you modify this file, please enter your name below and provide contact
	information in MaxsiDistributionContributors.h. For more information please see
	MaxsiDistributionContributors.h.
	
	Contributors to this file:

	- Jonas 'Sortie' Termansen
	- [your name here]

	MaxsiDistribution.dll
	Distributing since 2008

	MaxsiAchievements001.h
	An interface to Achievements.

****************************************************************************/

#ifndef MaxsiAchievements001_H
#define MaxsiAchievements001_H

//=============================================================================
// Undef all redirections to previous versions of this interface and make sure
// all the interfaces we refer to are properly versioned here. It doesn't
// matter if these interfaces are not the newest versions, just as long as
// as these def's refer to the used versions.
//=============================================================================
// Maxsi Achievement
#ifdef MaxsiAchievement
#undef MaxsiAchievement
#endif
#define MaxsiAchievement MaxsiAchievement001

// Maxsi Achievements Interface
#ifdef MaxsiAchievementsInterface
#undef MaxsiAchievementsInterface
#endif
#define MaxsiAchievementsInterface MaxsiAchievementsInterface001

// Maxsi Distribution Module
#ifdef MaxsiDistributionModule
#undef MaxsiDistributionModule
#endif
#define MaxsiDistributionModule MaxsiDistributionModule001

// Maxsi Distribution Interface
#ifdef MaxsiDistributionInterface
#undef MaxsiDistributionInterface
#endif
#define MaxsiDistributionInterface MaxsiDistributionInterface001

//=============================================================================
// Declare the Interface.
//=============================================================================
MD_DECLARE_INTERFACE_H(MaxsiAchievementsInterface);

//=============================================================================
// Maxsi Achievements declarations/definitions
//=============================================================================
#define MD_ACHIEVEMENT_LOCKED	0x00000000
#define MD_ACHIEVEMENT_UNLOCKED	0xFFFFFFFF

//=============================================================================
// Maxsi Achievement Data Class Interface
//=============================================================================
class	MaxsiAchievement
{
public:
	MaxsiAchievement();
	~MaxsiAchievement();

	//=============================================================================
	//	char* GetAchievementName();
	//
	//	Returns a string with the name of this achievement.
	//=============================================================================

	virtual	MESTR*			GetAchievementName() MD_DLL_INTERFACE;

	//=============================================================================
	//	char* GetAchievementDescription();
	//
	//	Returns a string with the description of this achievement.
	//=============================================================================

	virtual	MESTR*			GetAchievementDescription() MD_DLL_INTERFACE;

	//=============================================================================
	//	unsigned int SetAchievementProgress(unsigned int NewProgress);
	//
	//	Sets the progress of this achievement.
	//=============================================================================

	virtual	unsigned int	SetAchievementProgress(unsigned int NewProgress) MD_DLL_INTERFACE;

	//=============================================================================
	//	unsigned int GetAchievementProgress();
	//
	//	Returns the progress for this achievement.
	//=============================================================================

	virtual	unsigned int	GetAchievementProgress() MD_DLL_INTERFACE;

	//=============================================================================
	//	unsigned int GetAchievementProgressMax();
	//
	//	Returns the max progress for this achievement.
	//=============================================================================

	virtual	unsigned int	GetAchievementProgressMax() MD_DLL_INTERFACE;

	//=============================================================================
	//	bool IsSessionAchievement();
	//
	//	Returns whether this achievement is a session achievement. 
	//=============================================================================

	virtual	bool			IsSessionAchievement() MD_DLL_INTERFACE;

	//=============================================================================
	//	int LogoResourceId();
	//
	//	Returns an Id for the logo for this Achievement that can later be retrieved
	//	from the MaxsiAchievementsInterface class.
	//=============================================================================

	virtual	int				LogoResourceId() MD_DLL_INTERFACE;

public:
	MESTR*			AchievementName;
	MESTR*			AchievementDesc;
	unsigned int	Progress;
	unsigned int	ProgressMax;
	bool			SessionAchievement;
	int				ResourceId;

};

//=============================================================================
// Maxsi Achievements Interface
//=============================================================================
class	MaxsiAchievementsInterface : public MaxsiDistributionModule
{
public:
	MaxsiAchievementsInterface();
	~MaxsiAchievementsInterface();

	//=============================================================================
	//	bool	GetAchievements(MaxsiAchievement*** ListOut, size_t* NumOut);
	//
	//	If returns true, the MaxsiAchievement** member pointed to by ListOut is now
	//	filled with a pointer pointing to an array of MaxsiAchievement* members
	//	each pointing to an achievement. The size_t pointed to by Numout is filled
	//	with an integer descibing how many entires are in the array pointed to by
	//	the member pointed to by ListOut. When done, call DeleteAchievementList()
	//	with the member pointed to by ListOut and the member pointed to by NumOut.
	//=============================================================================

	virtual	bool	GetAchievements(MaxsiAchievement*** ListOut, size_t* NumOut) MD_DLL_INTERFACE;

	//=============================================================================
	//	bool	DeleteAchievementList(MaxsiAchievement** ListOut, size_t NumOut);
	//
	//	Deletes this achievement array with NumOut members.
	//=============================================================================

	virtual	bool	DeleteAchievementList(MaxsiAchievement** ListOut, size_t NumOut) MD_DLL_INTERFACE;

	//=============================================================================
	//	MaxsiAchievement*	GetAchievement(MESTR* Achievement);
	//
	//	Returns the achievement Achievement if such one is found, otherwise NULL.
	//=============================================================================

	virtual	MaxsiAchievement*	GetAchievement(MESTR* Achievement) MD_DLL_INTERFACE;

	//=============================================================================
	//	bool	UnlockAchievement(MESTR* Achievement);
	//
	//	Unlocks the achievement called Achievement for the current user and
	//	contacts the master server if it was previously locked.
	//=============================================================================

	virtual	bool	UnlockAchievement(MESTR* Achievement) MD_DLL_INTERFACE;

	//=============================================================================
	//	bool	LockAchievement(MESTR* Achievement);
	//
	//	Unlocks the achievement called Achievement for the current user and
	//	contacts the master server if it was previously unlocked.
	//=============================================================================

	virtual	bool	LockAchievement(MESTR* Achievement) MD_DLL_INTERFACE;

	//=============================================================================
	//	bool	SetAchievementProgress(MESTR* Achievement) = 0;
	//
	//	Sets the progress for the achievement called Achievement and contacts
	//	the master server if it has changed.
	//=============================================================================

	virtual	bool	SetAchievementProgress(MESTR* Achievement, unsigned int Progress) MD_DLL_INTERFACE;
	
	//=============================================================================
	//	unsigned int	GetAchievementProgress(MESTR* Achievement);
	//
	//	Returns the progress for this achievement.
	//=============================================================================

	virtual	unsigned int	GetAchievementProgress(MESTR* Achievement) MD_DLL_INTERFACE;
	
	//=============================================================================
	//	unsigned int	GetAchievementProgressMax(MESTR* Achievement);
	//
	//	Returns the max progress for this achievement.
	//=============================================================================

	virtual	unsigned int	GetAchievementProgressMax(MESTR* Achievement) MD_DLL_INTERFACE;

	//=============================================================================
	//	bool	IncrementAchievementProgress(MESTR* Achievement, [unsigned int Progress = 1]);
	//
	//	Increments the progress for the achievement Achievement with the optional
	//	amount Progress. Unlocks the Achievement if adding progress hits the
	//	achievement progress max. The Master Server is contacted if Progress is
	//	not 0 and Achievement is not a session achievement. The Master Server is
	//	not contacted, if Achievement is a session achievement, unless Progress
	//	hits the max.
	//=============================================================================

	virtual bool	IncrementAchievementProgress(MESTR* Achievement, unsigned int Progress = 1) MD_DLL_INTERFACE;

	//=============================================================================
	//	bool	DecrementAchievementProgress(MESTR* Achievement, [unsigned int Progress = 1]);
	//
	//	Decrements the progress for the achievement Achievement with the optional
	//	amount Progress. Unlocks the Achievement if adding progress hits the
	//	achievement progress max. Master Server is contacted if Progress is not 0.
	//=============================================================================

	virtual bool	DecrementAchievementProgress(MESTR* Achievement, unsigned int Progress = 1) MD_DLL_INTERFACE;

	//=============================================================================
	//	bool IsSessionAchievement(MESTR* Achievement);
	//
	//	Returns whether this achievement is a session achievement. 
	//=============================================================================

	virtual	bool	IsSessionAchievement(MESTR* Achievement) MD_DLL_INTERFACE;

	//=============================================================================
	//	bool	SessionFailedUnlock(MESTR* Achievement);
	//
	//	This per-session attempt to unlock Achievement failed.
	//=============================================================================

	virtual	bool	SessionUnlockFailed(MESTR* Achievement) MD_DLL_INTERFACE;
	
	//=============================================================================
	//	bool	SessionUnlockAttempt(MESTR* Achievement);
	//
	//	This per-session attempt to unlock Achievement has not failed yet.
	//=============================================================================

	virtual	bool	SessionUnlockAttempt(MESTR* Achievement) MD_DLL_INTERFACE;
	
	//=============================================================================
	//	bool	SessionFailedUnlock(MESTR* Achievement);
	//
	//	All session achievements - that has not failed yet - are hereby completed.
	//	The Master Server is instantly contacted and notified by the success, if
	//	any achievements were unlocked. The Master Server is not contacted if no
	//	session achievements were unlocked.
	//=============================================================================

	virtual	bool	SessionUnlockSucceded(MESTR* Achievement) MD_DLL_INTERFACE;

	//=============================================================================
	//	int LogoResourceId(MESTR* Achievement);
	//
	//	Returns an Id for the logo for this Achievement that can later be retrieved
	//	from the MaxsiAchievementsInterface class.
	//=============================================================================

	virtual	int		LogoResourceId(MESTR* Achievement) MD_DLL_INTERFACE;

	//=============================================================================
	//	bool GetLogoResource(char** BufferOut, size_t* BufferLengthOut, int ResourcId, int AchievementStatus );
	//
	//	Returns true if BufferOut gives a data buffer containing BufferLengthOut
	//	bytes giving the resource pointed by ResourceId and AchievementStatus
	//	which takes the two values: MD_ACHIEVEMENT_UNLOCKED and
	//	MD_ACHIEVEMENT_LOCKED.
	//=============================================================================

	virtual	bool	GetLogoResource(char** BufferOut, size_t* BufferLengthOut, int ResourcId, int AchievementStatus ) MD_DLL_INTERFACE;

	//=============================================================================
	//	char*	GetModuleName()
	//
	//	Returns a static string with the name of this particular MD Module.
	//=============================================================================

	virtual	MESTR*	GetModuleName() MD_DLL_INTERFACE;
	
	//=============================================================================
	//	bool	SetMaxsiDistributionInterface(MaxsiDistributionInterface* Interface)
	//
	//	Sets the the Maxsi Distribution main interface that modules should
	//	communicate through.
	//=============================================================================

	virtual	bool	SetMaxsiDistributionInterface(MaxsiDistributionInterface* Interface) MD_DLL_INTERFACE;

	//=============================================================================
	//	bool	CreateSession();
	//
	//	Terminates all data belonging to previous sessions and creates a new default
	//	session. A ses
	//=============================================================================

	virtual bool	CreateSession() MD_DLL_INTERFACE;

	//=============================================================================
	//	bool	SaveSession(char** OutBuffer, size_t* OutBufferLength);
	//
	//	Exports a buffer with all the session-data this module needs to store
	//	permanently for this session specificly. The application should take care
	//	of storing this and passing it onto RestoreSession() when the session is
	//	restored. OutBuffer points to a	char* which will be changed to point to a
	//	buffer containing OutBufferLength bytes that should be saved. Call
	//	SavedSession() when done with the buffer.
	//=============================================================================

	virtual bool	SaveSession(char** OutBuffer, size_t* OutBufferLength) MD_DLL_INTERFACE;

	//=============================================================================
	//	bool	SavedSession(char* OutBuffer, size_t OutBufferLength);
	//
	//	Deletes the buffer allocated for use by the application when SaveSession()
	//	is called. You must call SavedSession() when done with the buffer.
	//=============================================================================
	
	virtual bool	SavedSession(char* OutBuffer, size_t OutBufferLength) MD_DLL_INTERFACE;

	//=============================================================================
	//	bool	RestoreSession(char* OutBuffer, size_t OutBufferLength);
	//
	//	Restores a previous session.
	//=============================================================================

	virtual bool	RestoreSession(char* Buffer, size_t BufferLength) MD_DLL_INTERFACE;

public:
	MaxsiDistributionInterface* MDInterface;
	MaxsiAchievement**			Achievements;
	size_t						NumAchievements;

};

#endif